/*  Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
 */



#include "stdafx.h"
#include "NewTon核心.h"


#ifdef _DEBUG 

#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dAnimation_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dContainers_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dCustomJoints_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dgCore_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dgNewtonAvx2_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dgNewtonSse4.2_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dgPhysics_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dMath_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dModel_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dNewton_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dScene_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/dVehicle_d.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Debug/newton_d.lib")

#else

#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dAnimation.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dContainers.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dCustomJoints.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dgCore.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dgNewtonAvx2.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dgNewtonSse4.2.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dgPhysics.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dMath.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dModel.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dNewton.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dScene.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/dVehicle.lib")
#pragma comment(lib,"D:/U/DEV/newton_dynamics/lib/Release/newton.lib")


#endif


#include <矩阵.h>



S_NewTon核心::S_NewTon核心()
{
	m_物理世界 = NewtonCreate();


	auto ShapeA = NewtonCreateBox(m_物理世界, 1, 1, 1, NULL, 0);

	/*Mat44f mat;
	f_构建单位矩阵(&mat);
	auto 刚体A = NewtonCreateDynamicBody(m_物理世界, ShapeA, (float32*)&mat);
	NewtonBodySetMassMatrix(刚体A, -9.8f, 1, 1, 1);
	NewtonBodySetLinearDamping(刚体A, 0.0);
	float32 a[3] = { 0.0, 0.0, 0.0 };
	NewtonBodySetTorque(刚体A, a);

	mat.m30 = 3;
	auto 刚体B = NewtonCreateDynamicBody(m_物理世界, ShapeA, (float32*)&mat);
	NewtonBodySetMassMatrix(刚体B, 10.0f, 1, 1, 1);
	NewtonBodySetLinearDamping(刚体B, 0.0);
	NewtonBodySetTorque(刚体B, a);


	
	for (uint32 i = 0; i < 100000000; ++i) {
		NewtonUpdate(m_物理世界, 0.05);
		vec3 pos;
		vec3 posB;
		NewtonBodyGetPosition(刚体A, (float32*)&pos);
		NewtonBodyGetPosition(刚体B, (float32*)&posB);
		std::cout << "pos A: x=" << pos.x << " y=" << pos.y << " z=" << pos.z << std::endl;
		std::cout << "pos B: x=" << posB.x << " y=" << posB.y << " z=" << posB.z << std::endl;
		//});
	}*/






	//NewtonSetThreadsCount(m_物理世界, 48);
	//NewtonSetSolverIterations(m_物理世界, 1);
	NewtonSetSolverIterations(m_物理世界, 1);
	//NewtonSetPlatformArchitecture()
	dVector minSize(-500.0f, -500.0f, -500.0f);
	dVector maxSize(500.0f, 500.0f, 500.0f);
	//NewtonSetWorldSize(g_world, &minSize[0], &maxSize[0]);
	NewtonSetParallelSolverOnLargeIsland(m_物理世界, 1);
	//auto g_newtonDebugger = NewtonDebuggerCreateServer();
}

S_NewTon核心::~S_NewTon核心()
{
	NewtonDestroy(m_物理世界);
}
